# -*- coding: utf-8 -*-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：getBaseInfo.py
#日期：2019-11-04
#备注：获取一些基本信息，比如：手机号，身份证，姓名，案件号等等
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

from datetime import datetime
# from pycacho.cachobase.deal_excel import row_commonWrite

td_date = datetime.now().strftime('%Y%m%d')   # '20191104'

def get_reqNo(type,num):
    if num > 9999999:
        print("无法生成" + str(num) + '数量的流水号；' + '最多生成' + '9999999' + '数量的姓名！')
    else:
        reqNos = []
        for i in range(1,num+1):
            reqNo = type + td_date + '%07d'%(i)    # 8+7
            #print(reqNo)
            reqNos.append(reqNo)
        return reqNos

def get_phone(num):
    if num > 99999:
        print("无法生成" + str(num) + '数量的流水号；' + '最多生成' + '99999' + '数量的姓名！')
    else:
        phones = []
        for i in range(1,num+1):
            phone = '130000' + '%05d'%(i)    # 6+5
            #print(phone)
            phones.append(phone)
        return phones

 #total = 25*25*25=15625

def get_name(num):
    name_list = ['测','试','一','二','三','四','五','六','七','八','九','十','刘','李','王','张','曾','黄','孙','曹','天','下','第','地','底']
    n = int(pow(num, 1.0/3)) +1
    if n > len(name_list):
        print("无法生成"+str(num) + '数量的姓名；' + '最多生成' + str(pow(len(name_list), 3)) + '数量的姓名！' )
    else:
        names = []
        for i in range(n):
            for j in range(n):
                for k in range(n):
                    name = name_list[i] + name_list[j] + name_list[k]
                    names.append(name)
        return names

# type=CW,LW 最大
def get_processNo(type,num):
    if num > 999999:
        print("无法生成" + str(num) + '数量的案件号；' + '最多生成' + '999999' + '数量的案件！')
    else:
        processNos = []
        for i in range(1, num + 1):
            processNo = type  + td_date + 'HB'+ '%06d' % (i)  # 12+6
            #print(processNo)
            processNos.append(processNo)
        return processNos

# type=CI,HB
def get_usrNo(type,num):
    if num > 999999:
        print("无法生成" + str(num) + '数量的用户号；' + '最多生成' + '999999' + '数量的用户！')
    else:
        usrNos = []
        for i in range(1, num + 1):
            usrNo = type + td_date + '%06d' % (i)
            #print(usrNo)
            usrNos.append(usrNo)
        return usrNos

def get_idCard(num):
    checkCode = {
        0: '1',
        1: '0',
        2: 'X',
        3: '9',
        4: '8',
        5: '7',
        6: '6',
        7: '5',
        8: '4',
        9: '3',
        10: '2'
    }
    # 总数量=regions个数*birthdays个数
    idCards = []
    regions = ['650102','650104','650109','650106']
    #birthdays = ['19871103','19871104','19871105','19871106','19871107']
    birthdays = ['19900925']
    n = int(num/len(regions)/len(birthdays))  +1                    # 4*5*999=20*999=19980个
    if n +101 >999:
        print("无法生成" + str(num) + '数量的身份证;' + '最多生成' + str(999*len(regions)*len(birthdays))+ '数量的身份证！')
    else:
        for region in regions:
            for birthday in birthdays:
                for i in range(101,n+101):
                    idCard = region+birthday+str(i)
                    S = int(idCard[0:1]) * 7 + int(idCard[1:2]) * 9 + int(idCard[2:3]) * 10 + int(idCard[3:4]) * 5 + int(
                    idCard[4:5]) * 8 + int(idCard[5:6]) * 4 + int(idCard[6:7]) * 2 + int(idCard[7:8]) * 1 \
                    + int(idCard[8:9]) * 6 + int(idCard[9:10]) * 3 + int(idCard[10:11]) * 7 \
                    + int(idCard[11:12]) * 9 + int(idCard[12:13]) * 10 + int(idCard[13:14]) * 5 + int(
                    idCard[14:15]) * 8 + int(idCard[15:16]) * 4 + int(idCard[16:17]) * 2
                    Y = S % 11
                    last_code = checkCode[Y]
                    # print(S,Y,last_code)
                    id_card = idCard + last_code
                    idCards.append(id_card)
    #print("生成身份证个数为：", len(idCards))
    #print(idCards)
    return(idCards)


def process_msydloan(num):
    brwOrdNo = get_reqNo('560', num)
    #print(brwOrdNo)
    usrIdName = get_name(num)
    #print(usrIdName)
    usrIdCard = get_idCard(num)
    #print(usrIdCard)
    mblNo = get_phone(num)
    new_list = []
    for i in range(num):
        row = []
        row.append(usrIdCard[i])
        row.append(usrIdName[i])
        row.append(brwOrdNo[i])
        row.append(mblNo[i])
        new_list.append(row)
    #print(new_list)
    return new_list
    #row_commonWrite(new_list,'E:\zenglingwei\\test','msydloan.xls','test')

def process_msydonline(num):
    brwOrdNo = get_reqNo('msydonline_', num)
    mobileNo = get_phone(num)
    idCardUserName = get_name(num)
    idCardNo = get_idCard(num)

    new_list = []
    for i in range(num):
        row = []
        row.append(brwOrdNo[i])
        row.append(mobileNo[i])
        row.append(idCardUserName[i])
        row.append(idCardNo[i])

        new_list.append(row)
    return new_list

def process(num):
    qryCreditId = get_reqNo('002647', num)
    usrIdName = get_name(num)
    usrIdCard = get_idCard(num)
    mblNo = get_phone(num)
    process_cw = get_processNo('CW', num)
    process_lw = get_processNo('LW', num)
    brwOrdNo = get_reqNo('560', num)
    new_list = []
    for i in range(num):
        row = []
        row.append(qryCreditId[i])
        row.append(usrIdName[i])
        row.append(usrIdCard[i])
        row.append(mblNo[i])
        row.append(process_cw[i])
        row.append(process_lw[i])
        row.append(brwOrdNo[i])
        new_list.append(row)
    return new_list
    #row_commonWrite(new_list,'E:\zenglingwei\\test','msydloan.xls','test')


if __name__ == '__main__':
    #get_reqNo('0',10000000)
    #get_phone(10000)
    #get_name(20000)
    #get_idCard(100)
    #get_processNo('CW', 10)
    #get_usrNo('HB',10)
    #get_idCard(100000)
    process(5)

